﻿using System.Text;
namespace MiniCore;

public static partial class Extensions
{
    /// <summary>
    /// 注册了一个自定义服务器
    /// </summary>
    public static IWebHostBuilder UseHttpListener(this IWebHostBuilder builder, params string[] urls) => builder.UseServer(new HttpListenerServer(urls));

    public static Task WriteAsync(this HttpResponse response, string content)
    {
        var buffer = Encoding.UTF8.GetBytes(content);
        return response.Body.WriteAsync(buffer, 0, buffer.Length);
    }
    public static T Get<T>(this IFeatureCollection features) => features.TryGetValue(typeof(T), out var value) ? (T)value : default;

    public static IFeatureCollection Set<T>(this IFeatureCollection features, T feature)
    {
        features[typeof(T)] = feature;
        return features;
    }
}
